#include "Rectangle.h"		
Rectangle::Rectangle(){
	fx = 0;
	fy = 0;
	fwidth = 0;
	fheight = 0;
}
Rectangle::Rectangle(float fx, float fy, float fwidth, float fheight){
	this->fx = fx;
	this->fy = fy;
	this->fwidth = fwidth;
	this->fheight = fheight;
}

/* 
 * Collision Function
 * @Source:
 *  http://tekpool.wordpress.com/2006/10/11/rectangle-intersection-determine-if-two-given-rectangles-intersect-each-other-or-not/
 */
bool Rectangle::isCollision(Rectangle* other){

	float leastx = 0.0f,
		  leasty = 0.0f,
		  mostx = 0.0f,
		  mosty = 0.0f;
	if (this->fx < other->GetX()){
		leastx = this->fx;
		mostx =  other->GetX() +  other->GetWidth();
	}
	else{
		leastx = other->GetX();
		mostx = this->fx + this->fwidth;
	}
	if (this->fy < other->GetY()){
		leasty = this->fy;
		mosty = other->GetY() + other->GetHeight();
	}
	else{
		leasty = other->GetY();
		mosty = this->fy + this->fheight;
	}
	if (mostx - leastx >
		this->fwidth + other->GetWidth())
		return false;
	if (mosty - leasty >
		this->fheight + other->GetHeight())
		return false;
	return true;
}

// Setters and Getters
void Rectangle::SetX(float fx){
	this->fx = fx;
}
void Rectangle::SetY(float fy){
	this->fy = fy;
}
void Rectangle::SetWidth(float fwidth){
	this->fwidth = fwidth;
}
void Rectangle::SetHeight(float fheight){
	this->fheight = fheight;
}

float Rectangle::GetX(){
	return fx;
}
float Rectangle::GetY(){
	return fy;
}
float Rectangle::GetWidth(){
	return fwidth;
}
float Rectangle::GetHeight(){
	return fheight;
}